<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<!--
Created by Pau Rodriguez
Copyright using GPLv3

This XSLT script converts an RSS XML with Podcast to a generic M3U playlist
-->
<xsl:output method="text" encoding="iso-8859-1" indent="no"/><xsl:template match="/">
<xsl:text>#EXTM3U&#10;</xsl:text>
<xsl:for-each select="/rss/channel/item">
<xsl:choose>
<xsl:when test="itunes:duration">
<xsl:text>#EXTINF:</xsl:text>
<xsl:choose>
<xsl:when test="contains(itunes:duration,':')"><!-- Format HH:MM:SS -->
<xsl:value-of select="substring(itunes:duration,1,2) * 3600 +
                      substring(itunes:duration,4,2) * 60 +
                      substring(itunes:duration,7,2)"/>
</xsl:when>
<xsl:otherwise> <!-- Format SSSS -->
<xsl:value-of select="itunes:duration"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>,</xsl:text>
</xsl:when>
<xsl:otherwise><!-- No duration information -->
<xsl:text>#EXTINF:-1,</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="title"/><xsl:text>&#10;</xsl:text>
<xsl:value-of select="enclosure/@url"/><xsl:text>&#10;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
